﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Heaven.Graphics
{
    /// <summary>
    /// This class represents depth buffer
    /// </summary>
    public class DepthBuffer
    {
        #region Events

        /// <summary>
        /// Event occurs when a texture object has 
        /// been collected by GC (in other thread!)
        /// </summary>
        public event EventHandler GarbageCollected;

        /// <summary>
        /// This event for internal use only. It notices that 
        /// the device have to dispose this render target
        /// </summary>
        public event EventHandler DisposeRequested;

        #endregion

        #region Fields

        // Hash number (as a matter of 
        // fact it is just time stamp, two 
        // object can't be created
        // in equal time)
        long hash;

        // Size of this depth buffer
        int width, height;

        #endregion

        #region Properties

        /// <summary>
        /// Gets hash number
        /// </summary>
        public long Hash
        {
            get { return hash; }
        }

        /// <summary>
        /// Width
        /// </summary>
        public long Width
        {
            get { return width; }
        }

        /// <summary>
        /// Height
        /// </summary>
        public long Height
        {
            get { return height; }
        }

        #endregion

        #region Initialization

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="height">Height</param>
        /// <param name="width">Width</param>
        public DepthBuffer(int width, int height)
        {
            // Hash number (as a matter of fact it is just 
            // time stamp, two object can't create in equal time)
            hash = System.Diagnostics.Stopwatch.GetTimestamp();

            this.width = width;
            this.height = height;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Force disposing this render target immediately 
        /// </summary>
        public void Dispose()
        {
            if (DisposeRequested != null) DisposeRequested(this, EventArgs.Empty);
        }

        #endregion

        #region Destructor

        ~DepthBuffer()
        {
            if (GarbageCollected != null) GarbageCollected(this, EventArgs.Empty);
        }

        #endregion
    }
}
